package com.epam.OOP.application;

import com.epam.OOP.cargo.*;
import com.epam.OOP.coffee.BrazilCoffeeBuilder;
import com.epam.OOP.coffee.RobustaCoffeeBuilder;
import com.epam.OOP.tea.TeaBuilder;
import com.epam.OOP.transport.Transport;
import com.epam.OOP.transport.TransportType;
import com.epam.OOP.transport.VolumeChecker;
import com.epam.OOP.utils.PropertiesReader;

import java.io.UnsupportedEncodingException;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: Yelena_M
 * Date: 04.08.13
 * Time: 17:32
 * To change this template use File | Settings | File Templates.
 */
public class Application {

    public static void main(String[] args) throws UnsupportedEncodingException {
        PropertiesReader propertiesReader = new PropertiesReader();

        CargoLoader cargoLoader = new CargoLoader();  //Director

        CargoBuilder coffeeBuilder = new BrazilCoffeeBuilder(); //Abstract builder, ConcreteBuilder
        cargoLoader.setCargoBuilder(coffeeBuilder);
        cargoLoader.constructCargo();
        Cargo cargo = cargoLoader.getCargo(); //Product
        CargoSorter.sort(cargo);

        CargoBuilder teaBuilder = new TeaBuilder();
        cargoLoader.setCargoBuilder(teaBuilder);
        cargoLoader.constructCargo();
        cargo = cargoLoader.getCargo();
        CargoSorter.sort(cargo);

        CargoBuilder robustaCoffeeBuilder = new RobustaCoffeeBuilder();
        cargoLoader.setCargoBuilder(robustaCoffeeBuilder);
        cargoLoader.constructCargo();
        cargo = cargoLoader.getCargo();
        Set<Cargo> cargos = CargoSorter.sort(cargo);

        Transport van = new Transport("ID123", "VV", TransportType.VAN, cargos);
        van.loadCargo(VolumeChecker.cargoVolumeCount(cargos),
                      VolumeChecker.transportVolumeCount());

        CargoFinder.findByPrice(
                cargos,
                Integer.parseInt(propertiesReader.getProperties("finderVolumeFrom")),
                Integer.parseInt(propertiesReader.getProperties("finderVolumeTo")));

        CargoFinder.findByVolume(
                cargos,
                Integer.parseInt(propertiesReader.getProperties("finderPriceFrom")),
                Integer.parseInt(propertiesReader.getProperties("finderPriceTo")));
    }
}
